import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true,
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        // @ts-ignore
        component: () => import('@/views/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true },
      },
    ],
  },
  {
    path: '/ProjectInitiation',
    component: Layout,
    children: [
      {
        path: '',
        name: 'ProjectInitiation',
        component: () => import('@/views/ProjectInitiation/'),
        meta: { title: '项目立项', icon: 'tab' },
      },
    ],
  },
  {
    path: '/SparePartsList',
    name: '/SparePartsList',
    component: Layout,
    children: [
      {
        path: 'codeRule',
        name: 'codeRule',
        component: () => import('@/views/SparePartsList/codeRule/'),
        meta: { title: '项目预算', icon: 'monitor' },
      },
    ],
  },

  {
    path: '/Reimbursement',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Reimbursement',
        component: () => import('@/views/Reimbursement'),
        meta: { title: '通用报销', icon: 'money' },
      },
    ],
  },
  {
    path: "/AccountMatching",
    name: "/AccountMatching",
    component: Layout,
    children: [
      {
        path: "codeRule",
        name: "codeRule",
        component: () => import("@/views/AccountMatching/index"),
        meta: { title: "科目匹配", icon: "monitor" },
      },

    ]
  },
  {
    path: "/Statistics",
    name: "/Statistics",
    component: Layout,
    meta: { title: "统计查询", icon: "monitor" },
    children: [
      {
        path: "ProjectI",
        name: "ProjectI",
        component: () => import("@/views/Statistics/ProjectI/index"),
        meta: { title: "项目一", icon: "monitor" },
      },
      {
        path: "ItemII",
        name: "ItemII",
        component: () => import("@/views/Statistics/ItemII/index"),
        meta: { title: "项目二", icon: "monitor" },
      },
      {
        path: "Audit",
        name: "Audit",
        component: () => import("@/views/Statistics/Audit/index"),
        meta: { title: "项目审计验收报告", icon: "monitor" },
      },

    ]
  }
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = []

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err)
}
export default new Router({
  mode: 'hash', // 去掉url中的#
  base: '/admin/',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
})
